import path from 'path'
import common from './common'

let iceClass = 'EvidenceCourt.DBHelper'
let dllPath = path.resolve(process.execPath || '', '..\\EvidenceCourt.dll')
export default {
    async GetSysFonts() {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'GetSysFonts')
        } catch (error) {
            throw error
        }
    },
    async SetCoverTemplate(arg) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'SetCoverTemplate', arg)
        } catch (error) {
            throw error
        }
    },
    async SetCoverTemplateBackground(arg) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'SetCoverTemplateBackground', arg)
        } catch (error) {
            throw error
        }
    },
    async SetCoverBackground(arg) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'SetCoverBackground', arg)
        } catch (error) {
            throw error
        }
    },
    async GetEvidenceMaterial(arg, sid) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'GetEvidenceMaterial', {
                Files: arg,
                SlideID: sid
            })
        } catch (error) {
            throw error
        }
    },
    async DelEvidenceMaterial(id) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'DelEvidenceMaterial', {ID: id})
        } catch (error) {
            throw error
        }
    },
    async DelEvidenceMaterialByCode(arg) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'DelEvidenceMaterialByCode', arg)
        } catch (error) {
            throw error
        }
    },
    async GetLoginUserInfo(DBFile) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'GetLoginUserInfo', {DBFile})
        } catch (error) {
            throw error
        }
    },
    async ExecuteNonQuery(arg, DBFile = '', Password = '') {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'executeUpdates', arg && arg.executeSql ? arg.executeSql : arg)
        } catch (error) {
            throw error
        }
    },
    async ExecuteReaders(arg, DBFile, Password) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'ExecuteReaders', {DBFile, Password, executeSql: arg})
        } catch (error) {
            throw error
        }
    },
    async ExecuteReader(arg, DBFile, Password) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'executeQuerys', arg)
        } catch (error) {
            throw error
        }
    },
    async ExecuteFirstLine(arg, DBFile, Password) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'ExecuteFirstLine', {
                DBFile,
                Password,
                executeSql: arg
            })
        } catch (error) {
            throw error
        }
    },
    async ExecuteScalar(arg, DBFile, Password) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'executeScalar', arg)
        } catch (error) {
            throw error
        }
    },
    async DocumentConvertToImage(arg, DBFile, isSubmit = true, Password = 'Develop') {
        try {
            if (arg.append) {
                let _arg = new FormData()
                let iterator = arg.keys()
                let add = []
                for (let a of iterator) {
                    let b = add.find(function (item) {
                        return item === a
                    })
                    if (b) {
                        continue
                    }
                    let values = arg.getAll(a)
                    for (let item of values) {
                        _arg.append(a, item)
                    }
                    add.push(a)
                }
                return await common.ExecuteServer(dllPath, iceClass, 'DocumentConvertToImage', {
                    arg: _arg,
                    DBFile: DBFile,
                    Password: Password,
                    isSubmit: isSubmit
                })
            }
            return await common.ExecuteServer(dllPath, iceClass, 'DocumentConvertToImage', {
                DBFile: DBFile,
                Password: Password,
                Files: arg,
                isSubmit: isSubmit
            })
        } catch (error) {
            throw error
        }
    },
    async HtmlExportWord(arg) {
        try {
            return await common.ExecuteServer(dllPath, iceClass, 'HtmlExportWord', arg)
        } catch (error) {
            throw error
        }
    }
}
